﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Common
{
    public static class SQLSafe
    {
        public static string BeSafe_To_HTML(string str)
        {
            StringBuilder sb = new StringBuilder(str);
            sb.Replace("'", "&apos;");
            sb.Replace("-", "—");
            sb.Replace(";", "；");
            return sb.ToString();
        }
        public static string BeSafe_Back_HTML(string str)
        {
            StringBuilder sb = new StringBuilder(str);
            sb.Replace("&apos;", "'");
            sb.Replace("—", "-");
            sb.Replace("；", ";");
            return sb.ToString();
        }
        /// <summary>
        /// 是否安全
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static bool IsSafe(List<string> list)
        {
            string[] strs = { "'"};
            foreach (string var in list)
            {
                foreach (string c in strs)
                {
                    if (var.IndexOf(c) > -1)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
